package internet;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class SendDemo {
    public static void main(String[] args) throws IOException {

        // 创建发送对象192.168.0.102
        DatagramSocket ds = new DatagramSocket();

        // 创建数据 并打包// datagramPacket
        // 构造一个数据包
        byte[] bytes = "hello ,udp ,i am coming".getBytes();
        /*
        int length = bytes.length;
        InetAddress byName = InetAddress.getByName("192.168.0.102");
        int port = 10086;
        DatagramPacket dp = new DatagramPacket(bytes, length, byName, port);
        */
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length,InetAddress.getByName("192.168.0.102"),10086 );


        ds.send(dp);
        //关闭发送端
        ds.close();
    }

}
